home *** CD-ROM | disk | FTP | other *** search
- ;OCL{{{}}}
- ;OCL{{{ comments
- ; Jump from [,{ or ( to a matching ],} or ).
- ; if no match can be found, a errormessage appears.
- ; matching-fence-y and matching-fence-x are set to the calling position.
- ; if you use the function abort-hook-add in your abort handling function,
- ; pressing abort during search will move the cursor back to the calling
- ; position!
- ;OCL}}}
- @if-using not(ocl-file-go-match)
- @use (ocl-file-go-match)
- ;OCL{{{ libs
- @if-using not(ocl-file-error) @lib error @fi
- @if-using not(ocl-file-go-line) @lib go-line @fi
- @if-using not(ocl-file-pre-char) @lib pre-char @fi
- @if-using not(ocl-file-next-char) @lib next-char @fi
- @use ( language-ocl )
- @if-using not(ocl-file-userlang) @lib userlang @fi
- @use not( language-ocl )
- ;OCL}}}
- ;OCL{{{ vars
- ( defvar
- ( matching-fence-y ; calling-position
- matching-fence-x ; "
- matching-search ; is search active
- fence-counter ; number of found fences
- i-f ; complex fence leading character
- s-f ; start-fence-char or complex fence typ
- e-f ; end-fence-char
- d-f-1 ; first operation, used to move to next test position
- d-f-2 ; second operation, used to move to next test position
- )
- )
- ;OCL}}}
- ;OCL{{{ goto-matching-fence
- ( deffun goto-matching-fence
- ( if and(not(in-prompt) test-text)
- ;OCL{{{ goto
- (
- ;OCL{{{ store current x position
- set matching-fence-x store-pos
- ;OCL}}}
- ;OCL{{{ which fence-type
- set d-f-1 forward-text-character
- set d-f-2 no-operation
- set i-f 0
- case
- ;OCL{{{ ([{}])
- ( test-char "{ ( set s-f "{ set e-f "} ) )
- ( test-char "[ ( set s-f "[ set e-f "] ) )
- ( test-char "( ( set s-f "( set e-f ") ) )
- ( test-char "} ( set s-f "} set e-f "{ set d-f-1 previous-text-character ) )
- ( test-char "] ( set s-f "] set e-f "[ set d-f-1 previous-text-character ) )
- ( test-char ") ( set s-f ") set e-f "( set d-f-1 previous-text-character ) )
- ;OCL}}}
- default
- ;OCL{{{ #ifdef/#else/#endif @if-using/@fi
- ( set s-f 0
- screen-off
- ;OCL{{{ set s-f to complex fence typ
- ;OCL{{{ maybe ocl: -4 if-using/ -5 fi
- if test-language-ocl
- ( do
- ( if not(test-char "@) ( backward-character ) fi
- if test-char "@
- ( forward-character
- case
- ;OCL{{{ if-using
- ( test-str "if-using ( set s-f -5 ) )
- ;OCL}}}
- ;OCL{{{ fi
- ( test-str "fi ( set s-f -4 ) )
- ;OCL}}}
- default
- ;OCL{{{ not handled OCL-command
- ( backward-character )
- ;OCL}}}
- esac
- )
- fi
- )
- while and(>(store-pos 1) =(s-f 0))
- )
- fi
- ;OCL}}}
- ;OCL{{{ maybe cpp: -1 if / -2 else / -3 endif
- if =(s-f 0)
- ( beginning-of-line
- if test-char "#
- ( next-non-space-on-line
- case
- ;OCL{{{ if matches ifdef too
- ( test-str "if ( set s-f -2 ) )
- ;OCL}}}
- ;OCL{{{ else
- ( test-str "else ( set s-f -3 ) )
- ;OCL}}}
- ;OCL{{{ endif
- ( test-str "endif ( set s-f -1 )
- )
- ;OCL}}}
- esac
- )
- fi
- )
- fi
- ;OCL}}}
- ;OCL}}}
- screen-on
- case
- ;OCL{{{ no complex type given, return
- ( not(s-f)
- ( goto matching-fence-x
- refresh-line
- return-from-macro
- )
- )
- ;OCL}}}
- ;OCL{{{ ocl
- ( <(s-f -3)
- ( set i-f "@
- if =(s-f -4)
- ( set d-f-1 previous-text-character
- backward-character
- )
- else
- ( ;set d-f-1 forward-text-character
- ; this is the default
- )
- fi
- ;set d-f-2 no-operation
- ; this is the default
- )
- )
- ;OCL}}}
- default
- ;OCL{{{ cpp
- ( set i-f "#
- if =(s-f -1)
- ( set d-f-1 previous-text-line )
- else
- ( set d-f-1 next-text-line )
- fi
- set d-f-2 beginning-of-line
- )
- ;OCL}}}
- esac
- )
- ;OCL}}}
- esac
- ;OCL}}}
- ;OCL{{{ store current y position
- set matching-fence-y store-line
- ;OCL}}}
- message ( "[ M_SEARCH " "match "] )
- screen-off
- ;OCL{{{ search-loop
- set fence-counter 1
- set matching-search true
- do
- ( insert-ascii d-f-1
- insert-ascii d-f-2
- case
- ;OCL{{{ char-leading-complex-fence
- ( and(i-f test-char i-f)
- ( next-non-space-on-line
- case
- ;OCL{{{ ocl: if-using/fi
- ( <(s-f -3)
- ( case
- ;OCL{{{ if-using
- ( test-str "if-using
- ( if <>(s-f -4)
- ( set fence-counter +(fence-counter 1) )
- else
- ( set fence-counter -(fence-counter 1) )
- fi
- )
- )
- ;OCL}}}
- ;OCL{{{ fi
- ( and
- ( test-str "fi
- pre
- ( forward-character forward-character )
- or(test-char-set space test-end-line)
- )
- ( if <>(s-f -4)
- ( set fence-counter -(fence-counter 1) )
- else
- ( set fence-counter +(fence-counter 1) )
- fi
- )
- )
- ;OCL}}}
- esac
- ;OCL{{{ skip back to @
- do
- ( backward-character )
- while not(test-char "@ )
- ;OCL}}}
- )
- )
- ;OCL}}}
- default
- ;OCL{{{ cpp: if/else/endif
- ( case
- ;OCL{{{ if
- ( test-str "if
- ( if <>(s-f -1)
- ( set fence-counter +(fence-counter 1) )
- else
- ( set fence-counter -(fence-counter 1) )
- fi
- )
- )
- ;OCL}}}
- ;OCL{{{ else
- ( test-str "else
- ( if and(=(s-f -2) =(fence-counter 1))
- ( set fence-counter 0 )
- fi
- )
- )
- ;OCL}}}
- ;OCL{{{ endif
- ( test-str "endif
- ( if <>(s-f -1)
- ( set fence-counter -(fence-counter 1) )
- else
- ( set fence-counter +(fence-counter 1) )
- fi
- )
- )
- ;OCL}}}
- esac
- )
- ;OCL}}}
- esac
- )
- )
- ;OCL}}}
- ;OCL{{{ start-simple-fence
- ( test-char s-f ( set fence-counter +(fence-counter 1) ) )
- ;OCL}}}
- ;OCL{{{ end-simple-fence
- ( test-char e-f ( set fence-counter +(fence-counter -1)) )
- ;OCL}}}
- esac
- )
- while not(or(test-bottom test-top =(fence-counter 0)))
- set matching-search false
- ;OCL}}}
- if or(test-top test-bottom)
- ;OCL{{{ failed!
- ( set go-line-arg matching-fence-y
- go-line
- goto matching-fence-x
- screen-on
- redraw-display
- failed
- )
- ;OCL}}}
- else
- ;OCL{{{ show new position
- ( screen-on
- message ( )
- redraw-display
- )
- ;OCL}}}
- fi
- )
- ;OCL}}}
- fi
- )
- )
- ;OCL}}}
- ;OCL{{{ abort-hook-add
- @if-using not(ABORT-HOOK-ADD)
- @use (ABORT-HOOK-ADD)
- ( defmac abort-hook-add ( ) )
- @fi
- ( defmac abort-hook-add-saved ( abort-hook-add ) )
- ( undeclare ( abort-hook-add ) )
- ( defmac abort-hook-add
- ( if matching-search
- ( set matching-search false
- goto-line-mark matching-fence-y
- goto matching-fence-x
- )
- fi
- abort-hook-add-saved
- )
- )
- ( undeclare ( abort-hook-add-saved ) )
- ;OCL}}}
- ;OCL{{{ undeclare
- ( undeclare ( fence-counter i-f s-f e-f d-f-1 d-f-2 ) )
- ;OCL}}}
- @fi
-